﻿
using Authorized;
using CommandService;
using Entity;
using Entity.DbEntity;
using Entity.DbEntity.sys;
using Entity.SysEntity;
using Entity.ViewEntity;
using Entity.ViewEntity.sys;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace SysFrameWork
{
    public class SystemBLL : SysFrameWork.PubMethod
    {
        Commands cmd;
        Tools.TxtLogHelper txt;
        OperateModel oper;
        ReturnResult rsl;
        LoginInfo userLogin;
        public SystemBLL()
        {
            cmd = new Commands();
            txt = new Tools.TxtLogHelper();
            oper = new OperateModel();
            userLogin = new LoginInfo();
        }
        /// <summary>
        /// 获取当前登录人信息
        /// </summary>
        /// <returns></returns>
        public LoginUser getLoginInfo()
        {
            return userLogin.UserInfo();
        }
        /// <summary>
        /// 系统登录方法(统一方法)
        /// </summary>
        /// <param name="jsonStr">json字符串</param>
        /// <returns></returns>
        public ReturnResult login(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数丢失";
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    rsl.Message = "登录账号不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(json["userPwd"].ToString()))
                {
                    rsl.Message = "登录密码不允许为空";
                    return rsl;
                }

                #region 系统授权验证
                var loginRsl = CheckInService();
                if (!loginRsl.Result)
                {
                    rsl.Result = false;
                    rsl.Message = loginRsl.Message;
                    return rsl;
                }
                #endregion
                
                DbUser user = new DbUser();
                user.userCode = json["userCode"].ToString().Trim();
                user.userPwd = Tools.Encryption.DesEncrypt(json["userPwd"].ToString().Trim());
                user.status = "Y";
                var list = cmd.GetDataByObject<LoginUser>(user);
                if (list.Count > 0)
                {
                    string sql = "select * from sys_CustomerBase_info where dbCode='" + json["baseCode"] + "'";
                    var bTable = cmd.GetDataTable(sql);
                    if (bTable.Rows.Count > 0)
                    {
                        var arr = bTable.Rows[0]["baseName"].ToString().Split('_');
                        if (arr.Length < 2)
                        {
                            rsl.Message = "账号密码验证通过，但关联账套设置有误";
                            return rsl;
                        }
                        else
                        {
                            list[0].baseCode = arr[1];
                        }
                    }

                    rsl.Data = list[0];
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "账号或密码错误";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 导航信息菜单显示
        /// </summary>
        /// <param name="userCode">登录人账号</param>
        /// <param name="mType">菜单类型(PC/YD)</param>
        /// <returns></returns>
        public ReturnResult Navigation(string userCode, string mType = "")
        {
            rsl = new ReturnResult();
            try
            {
                string roleCode = "";
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from sys_MenuInfo ");
                sb.Append(" where status='Y' and isdel=0 ");
                if (string.IsNullOrWhiteSpace(mType))
                {
                    sb.Append(" and mType='PC'");
                }
                else
                {
                    sb.Append(" and mType='YD'");
                }
                var table = cmd.GetDataTable(sb.ToString());//获取全部有效菜单信息

                sb.Clear();
                sb.Append("select * from sys_powerConfig_groupPower where ");
                if (string.IsNullOrWhiteSpace(userCode))
                {//传递账号为空则显示当前登录人的身份信息
                    userCode = userLogin.UserInfo().userCode;
                    roleCode = userLogin.UserInfo().powerRole;
                }
                sb.Append("groupCode in(select powerRole from sys_users_info where userCode='" + userCode + "')");
                var uMenus = cmd.GetDataTable(sb.ToString());//获取用户菜单权限
                DataTable sTable = new DataTable();
                #region
                if (userLogin.UserInfo().isAdmin != 1)
                {
                    #region  非管理员身份
                    sTable = table.Clone();
                    List<string> mlist = new List<string>();
                    foreach (DataRow r in uMenus.Rows)
                    {
                        var dr = table.Select("menuCode='" + r["menuCode"].ToString() + "'");//查询菜单是否有效
                        if (dr.Length > 0)
                        {
                            if (!mlist.Contains(r["menuCode"].ToString()))
                            {
                                sTable.Rows.Add(dr[0].ItemArray);
                                mlist.Add(r["menuCode"].ToString());
                                if (dr[0]["parentMenu"] != null && !string.IsNullOrWhiteSpace(dr[0]["parentMenu"].ToString()))
                                {
                                    UserMenuData(dr[0]["parentMenu"].ToString(), table, ref sTable, ref mlist);
                                }

                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    sTable = table;//管理员身份直接获取全部身份信息
                }
                #endregion
                rsl.Data = this.CreateNavigationList(sTable);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getMenuList(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                string sv = Tools.ConfigReader.Reader["softType"];
                StringBuilder sb = new StringBuilder();
                sb.Append(" isdel=0 ");
                if (sv == "1" || (sv == "0" && userLogin.UserInfo().userCode != "admin"))
                {
                    sb.Append(" and status='Y' ");
                }
                if (!string.IsNullOrWhiteSpace(condition))
                {
                    var json = JsonConvert.DeserializeObject<JObject>(condition);
                    foreach (JProperty obj in json.Properties())
                    {
                        if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                        {
                            if (!string.IsNullOrWhiteSpace(sb.ToString()))
                            {
                                sb.Append(" and ");
                            }
                            if (obj.Name == "parentMenu")
                            {
                                sb.Append(" parentMenu= '" + obj.Value.ToString() + "' ");
                            }
                            else
                            {
                                sb.Append(obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                            }

                        }
                    }
                }
                rsl.Data = cmd.PageList("V_MenuInfo", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 保存菜单权限系统权限
        /// </summary>
        /// <param name="menuCode">菜单名称</param>
        /// <param name="powers">权限</param>
        /// <returns></returns>
        public ReturnResult saveMenuPower(string menuCode, string powers)
        {
            rsl = new ReturnResult();
            StringBuilder sb = new StringBuilder();
            try
            {
                sb.Append("select * from sys_dictionaries_info where ");
                sb.Append("types='pt' and status=1");
                var pTable = cmd.GetDataTable(sb.ToString());//全部权限数据
                var arr = powers.Split(',');
                var pnames = "";
                foreach (string str in arr)
                {
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        var dr = pTable.Select("code='" + str.Trim() + "'");
                        if (dr.Length < 1)
                        {
                            rsl.Message = string.Format("权限配置错了：{0}", str);
                            return rsl;
                        }
                        else
                        {
                            pnames += dr[0]["name"].ToString() + ",";
                        }
                    }
                }

                sb.Append("update sys_MenuInfo set operate='" + string.Format("{0};{1}", powers, pnames.TrimEnd(',')) + "'");
                sb.Append(" where menuCode='" + menuCode + "'");
                rsl = cmd.UpdateSql(sb.ToString());
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除导航菜单
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelMenuInfo(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                DbMenuInfo menu = new DbMenuInfo();
                menu.id = int.Parse(dataId);
                menu.isdel = 1;
                menu.deldate = getNow();
                menu.deluser = userLogin.UserInfo().userCode;
                oper = new OperateModel();
                oper.Conditions = "id";
                oper.Data = menu;
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 菜单数据添加
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult SaveMenuInfo(string datas)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(datas))
                {
                    rsl.Message = "保存参数丢失";
                    return rsl;
                }
                var data = JsonConvert.DeserializeObject<DbMenuInfo>(datas);
                if (string.IsNullOrWhiteSpace(data.menuCode))
                {
                    rsl.Message = "菜单编码不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(data.menuName))
                {
                    rsl.Message = "菜单名称不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(data.mType))
                {
                    rsl.Message = "菜单类型不允许为空";
                    return rsl;
                }
                string sql = "select * from sys_MenuInfo where menuCode='" + data.menuCode + "'";
                var table = cmd.GetDataTable(sql);
                if (data.id == null || data.id == 0)
                {
                    #region 添加操作
                    if (table.Rows.Count > 0)
                    {
                        rsl.Message = "编码已存在"; return rsl;
                    }
                    data.createtime = DateTime.Now.ToString();
                    data.createuser = userLogin.UserInfo().userCode;
                    data.operate = "view";
                    data.status = "Y";
                    data.isdel = 0;

                    if (string.IsNullOrWhiteSpace(data.parentMenu))
                    {
                        data.menuLevel = "1";
                    }
                    else
                    {
                        data.menuLevel = "2";
                    }
                    rsl = cmd.Add(data);
                    #endregion
                }
                else
                {
                    #region 编辑操作
                    List<OperateModel> operlist = new List<OperateModel>();
                    if (table.Rows.Count > 0)
                    {
                        if (data.id != int.Parse(table.Rows[0]["id"].ToString()))
                        {
                            rsl.Message = "编码已存在"; return rsl;
                        }
                    }
                    if (string.IsNullOrWhiteSpace(data.parentMenu))
                    {
                        data.menuLevel = "1";
                    }
                    else
                    {
                        data.menuLevel = "2";
                    }
                    OperateModel op = new OperateModel();
                    op.Conditions = "Id";
                    op.Data = data;
                    op.Types = OperateModel.OperateType.Edit;
                    operlist.Add(op);
                    #endregion

                    #region 对于菜单编码已经应用，需要关联修改
                    if (table.Rows.Count > 0)
                    {
                        string oldMenCode = table.Rows[0]["menuCode"].ToString();
                        DbUserPowers up = new DbUserPowers();
                        up.menuCode = oldMenCode;
                        var list = cmd.GetDataByObject<DbUserPowers>(up);
                        foreach (var p in list)
                        {
                            p.menuCode = data.menuCode;
                            op = new OperateModel();
                            op.Data = p;
                            op.Types = OperateModel.OperateType.Edit;
                            op.Conditions = "id";
                            operlist.Add(op);
                        }
                    }
                    #endregion

                    rsl = cmd.MoreUpdate(operlist);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取有效的菜单数据信息
        /// </summary>
        /// <param name="menuCode"></param>
        /// <returns></returns>
        public ReturnResult getEnableMenuInfo()
        {
            rsl = new ReturnResult();
            try
            {
                string sql = "select menuCode,menuName from sys_MenuInfo where status='Y' and isdel=0";
                var table = cmd.GetDataTable(sql);
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 根据菜单编码获取菜单详细
        /// </summary>
        /// <returns></returns>
        public ReturnResult getMenuByCode(string menuCode)
        {
            rsl = new ReturnResult();
            try
            {
                string sql = "select * from sys_MenuInfo where menuCode='" + menuCode + "'";
                var table = cmd.GetDataTable(sql);
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取顶级菜单数据
        /// </summary>
        /// <returns></returns>
        public ReturnResult GetTopMenu()
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select menuCode,menuName from sys_MenuInfo where menuLevel='1'");
                sb.Append(" and isdel=0 and status='Y' and mType='PC'");
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(table);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取指定菜单操作权限
        /// </summary>
        /// <param name="menuCode"></param>
        /// <returns></returns>
        public string getMenuOperate(string menuCode)
        {
            rsl = this.getMenuByCode(menuCode);
            if (rsl.Result)
            {
                var list = (List<Dictionary<string, string>>)rsl.Data;
                if (list.Count > 0 && !string.IsNullOrWhiteSpace(list[0]["operate"]))
                {
                    return list[0]["operate"];
                }
            }
            return "";
        }

        #region LayUiTree代码
        /// <summary>
        /// layui树结构
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public ReturnResult layUiTree(string userCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from sys_MenuInfo ");
                sb.Append(" where status='Y' and isdel=0 ");
                var table = cmd.GetDataTable(sb.ToString());//获取菜单全部信息
                rsl.Data = LayUiList(table);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 创建导航数据
        /// </summary>
        /// <param name="table">数据源</param>
        /// <returns></returns>
        private List<Dictionary<string, object>> LayUiList(DataTable table)
        {
            List<Dictionary<string, object>> menuList = new List<Dictionary<string, object>>();
            #region 构建数据
            var fMenu = table.Select("menuLevel=1 and mType='pc'").OrderBy(x => x["orderNum"]).CopyToDataTable();//获取所有父级菜单
            for (int i = 0; i < fMenu.Rows.Count; i++)
            {
                var fdic = new Dictionary<string, object>();
                fdic["title"] = fMenu.Rows[i]["menuName"].ToString();
                fdic["id"] = fMenu.Rows[i]["menuCode"].ToString();

                #region 子菜单
                List<Dictionary<string, object>> cList = new List<Dictionary<string, object>>();
                this.LayChildUrl(table, fMenu.Rows[i]["menuCode"].ToString(), fMenu.Rows[i]["menuName"].ToString(), ref cList);
                fdic["children"] = cList;
                #endregion
                menuList.Add(fdic);
            }
            var mdic = new Dictionary<string, object>();
            mdic["title"] = "移动端权限";
            mdic["id"] = "ydapp";
            StringBuilder sb = new StringBuilder();
            var mpDr = table.Select("mType='APP' and menuLevel='1'");
            List<Dictionary<string, object>> apList = new List<Dictionary<string, object>>();
            if (mpDr.Length > 0)
            {
                Dictionary<string, object> adic;
                foreach (DataRow r in mpDr)
                {
                    adic = new Dictionary<string, object>();
                    adic["title"] = r["menuName"].ToString();
                    adic["id"] = r["menuCode"].ToString();
                    #region 子菜单
                    List<Dictionary<string, object>> cList = new List<Dictionary<string, object>>();
                    this.LayChildUrl(table, r["menuCode"].ToString(), r["menuCode"].ToString(), ref cList);
                    adic["children"] = cList;
                    if (cList == null || cList.Count < 1)
                    {
                        adic["operate"] = r["operate"].ToString();
                    }
                    #endregion
                    apList.Add(adic);
                }
            }

            mdic["children"] = apList;

            menuList.Add(mdic);
            #endregion
            return menuList;
        }
        /// <summary>
        /// 子菜单生成方法(递归)
        /// </summary>
        /// <param name="table"></param>
        /// <param name="menuCode"></param>
        /// <param name="menuName"></param>
        /// <param name="icon"></param>
        /// <param name="chlist"></param>
        private void LayChildUrl(DataTable table, string menuCode, string menuName, ref List<Dictionary<string, object>> chlist)
        {
            var dr = table.Select("parentMenu='" + menuCode + "'");
            if (dr.Length > 0)
            {
                var cMenus = dr.OrderBy(x => x["orderNum"]).CopyToDataTable();
                for (int x = 0; x < cMenus.Rows.Count; x++)
                {
                    List<Dictionary<string, object>> tempList = new List<Dictionary<string, object>>();
                    var cdic = new Dictionary<string, object>();
                    cdic["title"] = cMenus.Rows[x]["menuName"].ToString();
                    cdic["id"] = cMenus.Rows[x]["menuCode"].ToString();
                    LayChildUrl(table, cMenus.Rows[x]["menuCode"].ToString(), cMenus.Rows[x]["menuName"].ToString(), ref tempList);
                    cdic["children"] = tempList;
                    cdic["operate"] = cMenus.Rows[x]["operate"].ToString();
                    chlist.Add(cdic);
                }
            }
        }

        #endregion

        #region 获取客户数据账套默认编码
        /// <summary>
        /// 获取客户数据账套默认编码
        /// </summary>
        /// <returns></returns>
        public string getDefaultBaseCode()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select top 1 DbCode from sys_CustomerBase_info ");
            sb.Append("where isDefault='Y' order by id desc ");
            var table = cmd.GetDataTable(sb.ToString());
            if (table.Rows.Count > 0)
            {
                return table.Rows[0]["DbCode"].ToString();
            }
            else
            {
                return "";
            }
        }
        #endregion

        /// <summary>
        /// 客户数据保存
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult SaveBaseData(string datas)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(datas))
                {
                    rsl.Message = "保存参数丢失";
                    return rsl;
                }
                var data = JsonConvert.DeserializeObject<DbCustomBase>(datas);

                if (string.IsNullOrWhiteSpace(data.serverIp))
                {
                    rsl.Message = "IP地址不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(data.baseName))
                {
                    rsl.Message = "数据库账套不允许为空";
                    return rsl;
                }
                else
                {
                    var arr = data.baseName.Split('_');
                    data.DbCode = arr[1].Trim();
                }
                if (string.IsNullOrWhiteSpace(data.baseName))
                {
                    rsl.Message = "数据库名不允许为空";
                    return rsl;
                }
                string sql = "select * from sys_CustomerBase_info where DbCode='" + data.DbCode + "'";
                var table = cmd.GetDataTable(sql);
                if (data.Id == null || data.Id == 0)
                {
                    #region 添加操作
                    if (table.Rows.Count > 0)
                    {
                        rsl.Message = "编码已存在"; return rsl;
                    }
                    rsl = cmd.Add(data);
                    #endregion
                }
                else
                {
                    #region 编辑操作
                    if (data.Id != int.Parse(table.Rows[0]["Id"].ToString()))
                    {
                        rsl.Message = "编码已存在"; return rsl;
                    }
                    OperateModel op = new OperateModel();
                    op.Conditions = "Id";
                    op.Data = data;
                    op.Types = OperateModel.OperateType.Edit;
                    rsl = cmd.Edit(op);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 系统参数参加
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult SavePar(string datas)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(datas))
                {
                    rsl.Message = "保存参数丢失";
                    return rsl;
                }
                var data = JsonConvert.DeserializeObject<DbSysParameter>(datas);
                if (string.IsNullOrWhiteSpace(data.partype))
                {
                    rsl.Message = "参数类型不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(data.parCode))
                {
                    rsl.Message = "参数编码不允许为空";
                    return rsl;
                }

                string sql = "select * from sys_parameters_info where parCode='" + data.parCode + "'";
                var table = cmd.GetDataTable(sql);
                if (data.id == null || data.id == 0)
                {
                    #region 添加操作
                    if (table.Rows.Count > 0)
                    {
                        rsl.Message = "编码已存在"; return rsl;
                    }
                    data.createtime = DateTime.Now.ToString();
                    data.createuser = userLogin.UserInfo().userCode;
                    data.isDel = 0;
                    rsl = cmd.Add(data);
                    #endregion
                }
                else
                {
                    #region 编辑操作
                    if (table.Rows.Count > 0)
                    {
                        if (data.id != int.Parse(table.Rows[0]["id"].ToString()))
                        {
                            rsl.Message = "编码已存在"; return rsl;
                        }
                    }
                    OperateModel op = new OperateModel();
                    op.Conditions = "Id";
                    op.Data = data;
                    op.Types = OperateModel.OperateType.Edit;
                    rsl = cmd.Edit(op);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 客户端单点登录信息
        /// </summary>
        /// <param name="dataType"></param>
        /// <param name="usIp"></param>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult AddSSOLogin(string dataType, string usIp, string dataId)
        {
            ReturnResult rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                string id = Guid.NewGuid().ToString().Replace("-", "").ToLower();
                sb.Append("insert into sys_ClientSSo_info values('" + id + "','',");
                sb.Append("'" + userLogin.UserInfo().userCode + "','" + userLogin.UserInfo().userName + "','" + dataType + "'");
                sb.Append(",1,'" + DateTime.Now.ToString() + "','" + dataId + "','" + userLogin.UserInfo().baseCode + "')");
                rsl = cmd.UpdateSql(sb.ToString());
                if (rsl.Result)
                {
                    rsl.Data = id;
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 根据编码获取客户数据信息
        /// </summary>
        /// <param name="DbCode">数据编码</param>
        /// <param name="isAll">是否显示全部</param>
        /// <returns>编码为空返回全部</returns>
        public ReturnResult getCustomBaseByCode(string DbCode, bool isAll = false)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from sys_CustomerBase_info ");
                sb.Append("where status='Y' ");
                if (!string.IsNullOrWhiteSpace(DbCode))
                {
                    sb.Append(" and DbCode='" + DbCode + "'");
                }
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(table);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取系统字典数据方法
        /// </summary>
        /// <param name="types"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getDictionaryInfo(string types, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                string sql = "select code,name from sys_dictionaries_info where types='" + types + "' and status=1 ";
                if (!string.IsNullOrWhiteSpace(condition))
                {
                    sql = sql + condition;
                }
                var t = cmd.GetDataTable(sql);
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(t);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /////////////////////////////
        #region 创建导航数据
        /// <summary>
        /// 创建导航数据
        /// </summary>
        /// <param name="table">数据源</param>
        /// <returns></returns>
        private List<Dictionary<string, object>> CreateNavigationList(DataTable table)
        {
            List<Dictionary<string, object>> menuList = new List<Dictionary<string, object>>();
            #region 构建数据
            var fMenu = table.Select("menuLevel=1").OrderBy(x => x["orderNum"]).CopyToDataTable();//获取所有父级菜单
            for (int i = 0; i < fMenu.Rows.Count; i++)
            {
                var fdic = new Dictionary<string, object>();
                fdic["menuName"] = fMenu.Rows[i]["menuName"].ToString();
                fdic["menuIcon"] = fMenu.Rows[i]["menuIcon"].ToString();

                #region 子菜单
                List<Dictionary<string, object>> cList = new List<Dictionary<string, object>>();
                this.ChildUrl(table, fMenu.Rows[i]["menuCode"].ToString(), fMenu.Rows[i]["menuName"].ToString(), fMenu.Rows[i]["menuIcon"].ToString(), ref cList);
                fdic["child"] = cList;
                #endregion
                menuList.Add(fdic);
            }
            #endregion
            return menuList;
        }
        #endregion
        /// <summary>
        /// 子菜单生成方法(递归)
        /// </summary>
        /// <param name="table"></param>
        /// <param name="menuCode"></param>
        /// <param name="menuName"></param>
        /// <param name="icon"></param>
        /// <param name="chlist"></param>
        private void ChildUrl(DataTable table, string menuCode, string menuName, string icon, ref List<Dictionary<string, object>> chlist)
        {
            var dr = table.Select("parentMenu='" + menuCode + "'");
            if (dr.Length > 0)
            {
                var cMenus = dr.OrderBy(x => x["orderNum"]).CopyToDataTable();
                for (int x = 0; x < cMenus.Rows.Count; x++)
                {
                    List<Dictionary<string, object>> tempList = new List<Dictionary<string, object>>();
                    var cdic = new Dictionary<string, object>();
                    cdic["menuName"] = cMenus.Rows[x]["menuName"].ToString();
                    cdic["menuIcon"] = cMenus.Rows[x]["menuIcon"].ToString();
                    if (cMenus.Rows[x]["onclick"] == null || string.IsNullOrWhiteSpace(cMenus.Rows[x]["onclick"].ToString()))
                    {
                        cdic["onclick"] = "";
                    }
                    else
                    {
                        cdic["onclick"] = cMenus.Rows[x]["onclick"].ToString();
                    }
                    string webUrl = "";
                    if (cMenus.Rows[x]["menuPath"].ToString().IndexOf("?") > -1)
                    { //菜单已经存在了参数
                        webUrl = cMenus.Rows[x]["menuPath"].ToString() + "&menuCode=" + cMenus.Rows[x]["menuCode"].ToString();
                    }
                    else
                    {
                        webUrl = cMenus.Rows[x]["menuPath"].ToString() + "?menuCode=" + cMenus.Rows[x]["menuCode"].ToString();
                    }
                    cdic["url"] = webUrl;
                    ChildUrl(table, cMenus.Rows[x]["menuCode"].ToString(), cMenus.Rows[x]["menuName"].ToString(), cMenus.Rows[x]["menuIcon"].ToString(), ref tempList);
                    cdic["child"] = tempList;
                    chlist.Add(cdic);

                }

            }
        }

        #region 用户菜单权限
        /// <summary>
        /// 用户菜单权限
        /// </summary>
        /// <param name="pMenu">父级菜单编码</param>
        /// <param name="qtable">全部菜单</param>
        /// <param name="sTable">显示菜单</param>
        /// <param name="list">菜单编码集合</param>
        private void UserMenuData(string pMenu, DataTable qtable, ref DataTable sTable, ref List<string> list)
        {
            if (!string.IsNullOrWhiteSpace(pMenu))
            {
                if (!list.Contains(pMenu))
                {
                    var dr = qtable.Select("menuCode='" + pMenu + "'");
                    if (dr.Length > 0)
                    {
                        sTable.Rows.Add(dr[0].ItemArray);
                        list.Add(pMenu);
                        UserMenuData(dr[0]["parentMenu"].ToString(), qtable, ref sTable, ref list);
                    }
                }

            }
        }
        #endregion

        /// <summary>
        /// 获取系统权限
        /// </summary>
        /// <param name="types"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getSystemPowers(string types, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from sys_dictionaries_info where types='pt' and status=1 ");

                if (!string.IsNullOrWhiteSpace(condition))
                {
                    sb.Append(condition);

                }
                sb.Append(" order by  extendFile desc");
                var t = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(t);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 根据参数编码获取参数值
        /// </summary>
        /// <param name="parCode">参数编码</param>
        /// <param name="isAll">过滤删除</param>
        /// <returns></returns>
        public ReturnResult getParameterByCode(string parCode, bool isAll = false)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(parCode))
                {
                    rsl.Message = "关键参数为空";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from sys_parameters_info ");
                sb.Append("where parCode='" + parCode + "' ");
                if (isAll)
                {
                    sb.Append(" isDel=0");
                }
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "查无此参数";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 客户关联账套数据
        /// </summary>
        /// <returns></returns>
        public ReturnResult CustomBaseInfo()
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_CustomBaseInfo");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 系统参数列表模型
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">页面信息数</param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getParametersList(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {

                if (string.IsNullOrWhiteSpace(pageIndex))
                {
                    pageIndex = "1";
                }
                if (string.IsNullOrWhiteSpace(pageSize))
                {
                    pageSize = Tools.ConfigReader.Reader["PageSize"];
                }
                StringBuilder sb = new StringBuilder();
                sb.Append(" isdel=0 ");
                sb = CreateSelectCondition(sb, condition);

                var list = cmd.PageList<ViewParameterInfo>("V_parameterInfo", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 系统参数删除方法
        /// <param name="dataId">数据id</param>
        /// </summary>
        /// <returns></returns>
        public ReturnResult DelParmeter(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                DbSysParameter par = new DbSysParameter();
                par.isDel = 1;
                par.id = int.Parse(dataId);
                par.delTime = getNow();
                par.delUser = userLogin.UserInfo().userCode;
                OperateModel oper = new OperateModel();
                oper.Data = par;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取表格数据
        /// </summary>
        /// <param name="tCode"></param>
        /// <returns></returns>
        public ReturnResult GetTableCloums(string tCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(tCode))
                {
                    rsl.Message = "数据表编码丢失";
                    return rsl;
                }
                sb.Append("select * from sys_TableCloumns_config where tCode='" + tCode + "'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count < 1)
                {
                    rsl.Message = "数据表编码不存在";
                    return rsl;
                }
                rsl.Data = cmd.TableToDictionary(table);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 单点登录方法
        /// </summary>
        /// <param name="userCode">用户账号</param>
        /// <param name="baseCode">系统编码</param>
        /// <returns></returns>
        public ReturnResult ssoLogin(string userCode, string baseCode)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(userCode))
                {
                    rsl.Message = "参数丢失";
                    return rsl;
                }

                DbUser user = new DbUser();
                user.userCode = userCode;

                user.status = "Y";
                var list = cmd.GetDataByObject<LoginUser>(user);
                if (list.Count > 0)
                {
                    list[0].baseCode = baseCode;
                    rsl.Data = list[0];
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "登录失败";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        public string ToWebUrl(string plCode, string gxCode, string view)
        {
            StringBuilder sb = new StringBuilder();
            string dataId = "0";
            string url = "";
            if (gxCode.ToLower() != "cm")
            {
                sb.Append("select * from pi_ProductionPlan_process where ");
                sb.Append("plCode='" + plCode + "' and gxCode='" + gxCode + "'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    dataId = table.Rows[0]["id"].ToString();
                }
            }
            else
            {
                dataId = plCode;
            }
            string webCode = "";
            if (gxCode == "ys")
            {
                webCode = "Plan/GxYinShua";
            }
            else if (gxCode == "fh")
            {
                webCode = "GxFuhe";
            }
            else if (gxCode == "reqie")
            {
                webCode = "Plan/GxReQie";
            }
            else if (gxCode == "zhidai")
            {
                webCode = "Plan/GxZhiDai";
            }
            else if (gxCode == "zb")
            {
                webCode = "Plan/GxZheBian";
            }
            else if (gxCode == "cfzd")
            {
                webCode = "Plan/GxCeFengZhiDai";
            }
            else if (gxCode == "oushi")
            {
                webCode = "Plan/GxOushiZhiDai";
            }
            else if (gxCode == "fq")
            {
                webCode = "Plan/GxFenQie";
            }
            else if (gxCode == "cm")
            {
                webCode = "CMPlan/CMPlanUpdate";
            }
            url = string.Format("../{3}?dataId={0}&plCode={1}&view={2}", dataId, plCode, view, webCode);
            return url;
        }
        #region 保存信息发送记录
        /// <summary>
        /// 信息发送记录保存方法
        /// </summary>
        /// <param name="businessType">数据类型</param>
        /// <param name="bussnessId">数据ID</param>
        /// <param name="msgType">消息类型</param>
        /// <param name="toUsers">人员</param>
        /// <param name="contents">消息内容</param>
        /// <param name="isResult">结果</param>
        /// <param name="errMsg">错误消息</param>
        /// <param name="createuser">创建人员</param>
        /// <returns></returns>
        public ReturnResult AddRecords(string businessType, string bussnessId, string msgType, string toUsers, string contents, string isResult, string errMsg, string createuser)
        {
            DbSendMsg msg = new DbSendMsg();
            msg.contents = contents;
            msg.businessId = bussnessId;
            msg.createtime = DateTime.Now.ToString();
            msg.isResult = isResult;
            msg.id = Guid.NewGuid().ToString().Replace("-", "");
            msg.businessType = businessType;
            msg.msgType = msgType;
            msg.toUsers = toUsers;
            msg.createuser = createuser;
            msg.errMsg = errMsg;
            rsl = cmd.Add(msg);
            return rsl;
        }
        #endregion

        /// <summary>
        /// 收发类型数据同步
        /// </summary>
        /// <param name="isAuto"></param>
        /// <returns></returns>
        public ReturnResult SyncShouFa(bool isAuto = false)
        {
            rsl = new ReturnResult();
            SysFrameWork.SystemBLL sysBLL = new SysFrameWork.SystemBLL();
            OutBaseHelper cuHelper = new OutBaseHelper();
            var OperList = new List<OperateModel>();
            try
            {
                List<DbUser> UserList = new List<DbUser>();
                string baseCode = "";
                #region 账套选择
                if (isAuto)
                {
                    baseCode = sysBLL.getDefaultBaseCode();
                }
                else
                {
                    baseCode = userLogin.UserInfo().baseCode;
                }
                #endregion

                #region 同步收发信息
                StringBuilder sb = new StringBuilder();
                sb.Append("select cRdCode AS code, cRdName AS name,bRdFlag from Rd_Style");
                sb.Append(" where bRdEnd = 1  ");

                var rTable = cuHelper.getData(sb.ToString(), baseCode);//U8收发类型信息
                sb.Clear();
                sb.Append("select * from fun_CommonData_Info where cType='sf' ");
                var qTable = cmd.GetDataTable(sb.ToString());//获取所有收发类型信息

                if (rTable.Rows.Count > 0)
                {
                    DbCommonData cmData;
                    for (int i = 0; i < rTable.Rows.Count; i++)
                    {
                        cmData = new DbCommonData();
                        var dr = qTable.Select("cCode='" + rTable.Rows[i]["code"].ToString() + "'");
                        cmData.cCode = rTable.Rows[i]["code"].ToString();
                        cmData.cName = rTable.Rows[i]["name"].ToString();
                        cmData.delUser = rTable.Rows[i]["bRdFlag"].ToString();
                        cmData.isDel = 0;
                        cmData.status = "Y";
                        oper = new OperateModel();
                        if (dr.Length < 1)
                        {
                            cmData.cType = "SF";
                            cmData.cMemo = "收发类型";
                            cmData.createtime = getNow();
                            oper.Types = OperateModel.OperateType.Add;
                        }
                        else
                        {
                            oper.Types = OperateModel.OperateType.Edit;
                            oper.Conditions = "cCode";
                        }
                        oper.Data = cmData;
                        OperList.Add(oper);

                    }
                }
                #endregion
                rsl = cmd.MoreUpdate(OperList);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.ToString();
            }
            return rsl;
        }
        /// <summary>
        /// 清楚单点记录
        /// </summary>
        /// <returns></returns>
        public ReturnResult ClearSSORecord()
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                string sql = "delete from sys_ClientSSo_info";
                rsl = cmd.UpdateSql(sql);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tempCode"></param>
        /// <param name="d_table"></param>
        /// <returns></returns>
        public MemoryStream CreateExcel(string tempCode, DataTable d_table)
        {
            MemoryStream ms = null;
            try
            {
                string msg = "";
                int rCount = 0;
                StringBuilder sb = new StringBuilder();
                sb.Append("select isnull(columns,'') columns,memo from sys_TableCloumns_config where tcType='export'");
                sb.Append(" and tCode='" + tempCode + "'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count < 1 || string.IsNullOrWhiteSpace(table.Rows[0][0].ToString()))
                {
                    msg = "没有找到相关导出配置数据";
                    return null;
                }
                var files = JsonConvert.DeserializeObject<List<JObject>>(table.Rows[0][0].ToString());

                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                //添加一个sheet
                NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet(table.Rows[0]["memo"].ToString());
                IDataFormat dataformat = book.CreateDataFormat();
                ICell cell;

                var bodyStyle = ExcelBodyStyle(book, true);//单元格样式
                NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
                cell = row1.CreateCell(rCount);
                cell.SetCellValue(table.Rows[0]["memo"].ToString() + "列表");
                cell.CellStyle = ExcelTitleStyle(book, false);
                row1.Height = 550;
                rCount++;

                #region 绘制表头
                row1 = sheet1.CreateRow(rCount);
                row1.Height = 400;
                for (int i = 0; i < files.Count; i++)
                {
                    cell = row1.CreateCell(i);
                    cell.CellStyle = bodyStyle;
                    cell.SetCellValue(files[i]["fieldName"].ToString());
                }
                #endregion
                rCount++;
                for (int i = 0; i < d_table.Rows.Count; i++)
                {
                    row1 = sheet1.CreateRow(rCount);
                    row1.Height = 400;
                    for (int x = 0; x < files.Count; x++)
                    {
                        if (d_table.Columns.Contains(files[x]["fieldCode"].ToString()))
                        {
                            cell = row1.CreateCell(x);
                            #region 将数量、工资等信息导出为数值格式
                            if (files[x]["fieldCode"].ToString().Equals("sumNum") || files[x]["fieldCode"].ToString().Equals("yNum")
                               || files[x]["fieldCode"].ToString().Equals("nNum") || files[x]["fieldCode"].ToString().Equals("yPrice")
                               || files[x]["fieldCode"].ToString().Equals("nPrice") || files[x]["fieldCode"].ToString().Equals("total"))
                            {
                                //1、设置单元格格式
                                cell.SetCellType(CellType.Numeric);
                                cell.CellStyle = bodyStyle;
                                cell.SetCellValue(Double.Parse(d_table.Rows[i][files[x]["fieldCode"].ToString()].ToString()));
                            }
                            else
                            {
                                cell.CellStyle = bodyStyle;
                                cell.SetCellValue(d_table.Rows[i][files[x]["fieldCode"].ToString()].ToString());
                            }
                            #endregion

                            continue;
                        }
                    }
                    rCount++;
                }


                ms = new System.IO.MemoryStream();
                book.Write(ms);
                ms.Seek(0, SeekOrigin.Begin);

            }
            catch (Exception ex)
            {
                var p = ex;
            }

            return ms;
        }
        /// <summary>
        /// 获取系统授权码
        /// </summary>
        /// <returns></returns>
        public ReturnResult GetSysKeyCode()
        {
            rsl = new ReturnResult();
            bool isInit = false;
            try
            {
                var path = AppDomain.CurrentDomain.BaseDirectory;
                path = string.Format("{0}{1}.txt", path, Tools.ConfigReader.Reader["serFile"]);
                string content = "";
                Dictionary<string, string> keyInfo = new Dictionary<string, string>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                if (!System.IO.File.Exists(path))
                {
                    FileStream fs1 = new FileStream(path, FileMode.Create, FileAccess.Write);//创建写入文件 
                    fs1.Close();
                    isInit = true;

                }
                else
                {
                    StreamReader sr = new StreamReader(path, Encoding.Default);
                    content = sr.ReadToEnd();
                    sr.Dispose();
                    if (string.IsNullOrWhiteSpace(content))
                    {
                        isInit = true;
                    }

                }
                string errMsg = "";
                if (!isInit)
                {
                    var dJson = JsonConvert.DeserializeObject<JObject>(content);
                    try
                    {

                        keyInfo = JsonConvert.DeserializeObject<Dictionary<string, string>>(Tools.Encryption.DesDecrypt(dJson["keyCode"].ToString()));
                    }
                    catch (Exception ex)
                    {
                        errMsg = "授权码解析失败：" + ex.Message;
                    }

                    if (string.IsNullOrWhiteSpace(errMsg))
                    {
                        dic["keyCode"] = dJson["keyCode"].ToString();
                        dic["info"] = JsonConvert.SerializeObject(dJson);
                    }
                    else
                    {
                        dic["keyCode"] = "";
                        dic["info"] = errMsg;
                    }
                }
                else
                {
                    keyInfo["companyCode"] = "";
                    keyInfo["companyName"] = "";
                    keyInfo["startDate"] = getNowDate();
                    keyInfo["endDate"] = getNowDate(syDays);
                    dic["info"] = JsonConvert.SerializeObject(keyInfo);
                }


                rsl.Result = true;
                rsl.Data = dic;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        int syDays = 395;//软件试用时间   //23.12.4---24.12.5
        /// <summary>
        /// 保存系统授权码
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult SaveKeyCode(string datas)
        {
            SoftAuthorized sq = new SoftAuthorized();
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                if (string.IsNullOrWhiteSpace(json["jyCode"].ToString()))
                {
                    rsl.Message = "校验编码不允许为空";
                    return rsl;
                }
                string comCode = "", comName = "";
                if (!string.IsNullOrWhiteSpace(json["contents"].ToString()))
                {
                    var cJson = JsonConvert.DeserializeObject<JObject>(json["contents"].ToString());
                    if (!string.IsNullOrWhiteSpace(cJson["companyCode"].ToString()))
                    {
                        comCode = cJson["companyCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(cJson["companyName"].ToString()))
                    {
                        comName = cJson["companyName"].ToString();
                    }
                }
                if (string.IsNullOrWhiteSpace(comCode) || string.IsNullOrWhiteSpace(comName))
                {
                    rsl.Message = "注册信息填写不完整";
                    return rsl;
                }
                var info = sq.CreateNewKey(int.Parse(json["jyCode"].ToString()), syDays, false, comCode, comName, true);
                var d = JsonConvert.DeserializeObject<JObject>(info);
                if (bool.Parse(d["result"].ToString()))
                {
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = d["msg"].ToString();
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 验证用户是否在服务期内
        /// </summary>
        /// <returns></returns>
        public ReturnResult CheckInService()
        {
            rsl = new ReturnResult();

            // 开发环境跳过验证
            //rsl.Result = true;
            //return rsl;

            try
            {
                SoftAuthorized sq = new SoftAuthorized();
                var s = sq.CheckSysKeyCode();
                var json = JsonConvert.DeserializeObject<JObject>(s);
                if (bool.Parse(json["result"].ToString()))
                {
                    if (json["code"].ToString().Equals("210"))
                    {
                        rsl.Message = rsl.Message = json["msg"].ToString();
                    }
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = json["msg"].ToString();
                    rsl.Data = json["code"].ToString();
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
    }
}
